const MySql = require('mysql2/promise')
const utils = require('./utils')

module.exports = async (ctx, next) => {
    ctx.connid = 'rudy_sql_sign_passid'
    ctx.mysql = async () => {
        let cfg = utils.parse(ctx.cookies.get(ctx.connid))
        return await MySql.createConnection({
            host: cfg[0],
            user: cfg[1],
            password: cfg[2]
        });
    }
    await next()
}